home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS04.ADF / C / creaport.c < prev    next >
C/C++ Source or Header  |  1985-10-30  |  2KB  |  71 lines

  1. /***********************************************************************
  2. *
  3. *       Exec Support Functions -- Ports and Messages
  4. *
  5. ***********************************************************************/
  6.  
  7. #include "exec/types.h"
  8. #include "exec/nodes.h"
  9. #include "exec/lists.h"
  10. #include "exec/memory.h"
  11. #include "exec/interrupts.h"
  12. #include "exec/ports.h"
  13. #include "exec/libraries.h"
  14. #include "exec/tasks.h"
  15. #include "exec/execbase.h"
  16.  
  17.  
  18. extern APTR AllocMem();
  19. extern UBYTE AllocSignal();
  20. extern struct Task *FindTask();
  21.  
  22.  
  23. struct MsgPort *CreatePort (name, pri)
  24.     char *name;
  25.     BYTE  pri;
  26. {
  27.     UBYTE sigBit;
  28.     struct MsgPort *port;
  29.  
  30.     if ((sigBit = AllocSignal (-1)) == -1)
  31.         return ((struct MsgPort *) 0);
  32.  
  33.     port = AllocMem ((ULONG) sizeof (*port), MEMF_CLEAR | MEMF_PUBLIC);
  34.  
  35.     if (port == 0) {
  36.         FreeSignal (sigBit);
  37.         return ((struct MsgPort *) (0));
  38.     }
  39.  
  40.     port -> mp_Node.ln_Name = name;
  41.     port -> mp_Node.ln_Pri = pri;
  42.     port -> mp_Node.ln_Type = NT_MSGPORT;
  43.  
  44.     port -> mp_Flags = PA_SIGNAL;
  45.     port -> mp_SigBit = sigBit;
  46.     port -> mp_SigTask = FindTask (0);
  47.  
  48.     if (name != 0)
  49.         AddPort (port);
  50.     else
  51.         NewList (&(port -> mp_MsgList));
  52.  
  53.     return (port);
  54. }
  55.  
  56.  
  57.  
  58. DeletePort(port)
  59.     struct MsgPort *port;
  60. {
  61.     if ((port -> mp_Node.ln_Name) != 0)
  62.         RemPort (port);
  63.  
  64.     port -> mp_Node.ln_Type = 0xff;
  65.     port -> mp_MsgList.lh_Head = (struct Node  *) - 1;
  66.  
  67.     FreeSignal (port -> mp_SigBit);
  68.  
  69.     FreeMem (port, (ULONG) sizeof (*port));
  70. }
  71.